import 'package:app_health/pages/login/LoginPage.dart';
import 'package:app_health/pages/regist/RegistPage.dart';
import 'package:app_health/pages/regist/SexPage.dart';
import 'package:app_health/utils/ImageUtils.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

class LoginHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return LoginState();
  }
}

class LoginState extends State<LoginHomePage> {
  /// 头部logo
  var topLogo = Align(
    alignment: Alignment.center,
    child: Container(
        margin: EdgeInsets.only(top: 100.0),
        child: Image.asset(
          ImageUtils.getImagePath('logo'),
          fit: BoxFit.fitWidth,
        )),
  );

  var topLogoBottomText = Align(
    alignment: Alignment.center,
    child: Container(
      margin: EdgeInsets.only(top: 22.0),
      child: Text(
        '为了您的健康我们一直在努力',
        style: TextStyle(fontSize: 12.0, color: Colors.grey),
      ),
    ),
  );

  Widget twoButton(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 95.0, left: 30.0, right: 30.0),
      child: Column(
        children: <Widget>[
          Container(
            width: double.infinity,
            height: 43.0,
            child: RaisedButton(
              textColor: Colors.white,
              onPressed: () {
                // ignore: implicit_this_reference_in_initializer
                Navigator.push(context,
                    MaterialPageRoute(builder: (context) => LoginPage()));
              },
              child: Text(
                '登录',
              ),
              elevation: 2.0,
              color: Color(0xFF0AD0B2),
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(20.0)),
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 20.0),
            height: 43.0,
            width: double.infinity,
            child: RaisedButton(
              textColor: Color(0xFF0AD0B2),
              onPressed: () {
                // 跳转注册界面
                _go2RegisterPage(context);
              },
              child: Text(
                '注册',
              ),
              elevation: 2.0,
              color: Colors.white,
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(20.0),
                  side: BorderSide(color: Color(0xFF0AD0B2), width: 1.0)),
            ),
          )
        ],
      ),
    );
  }

  ///登录静态提示文字
  Widget tipsWidget() {
    TapGestureRecognizer recognizer = TapGestureRecognizer();
    recognizer.onTap = () {
      Navigator.of(context).push(MaterialPageRoute(builder: (context){
        // 跳转选择男女界面
        return SexWidget();
      }));
    };

    return new Container(
      margin: const EdgeInsets.fromLTRB(0, 16.0, 0, 0),
      child: new RichText(
        text: new TextSpan(
          text: '登录即表示您同意',
          style: new TextStyle(color: Colors.grey, fontSize: 12.0),
          children: <TextSpan>[
            new TextSpan(
              recognizer: recognizer,
              text: '用户协议',
              style: new TextStyle(color: Color(0xFF0AD0B2), fontSize: 12.0),
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        brightness: Brightness.dark,
        backgroundColor: Colors.white,
        elevation: 0.0,
        iconTheme: IconThemeData(color: Colors.grey),
        leading: IconButton(
            icon: Icon(
              Icons.close,
            ),
            onPressed: () {
              Navigator.maybePop(context);
            }),
      ),
      body: Container(
        color: Colors.white,
        child: Column(
          children: <Widget>[
            topLogo,
            topLogoBottomText,
            twoButton(context),
            tipsWidget()
          ],
        ),
      ),
    );
  }

  void _go2RegisterPage(BuildContext context) {
    Navigator.push(context, MaterialPageRoute(builder: (context){
      return new RegistPage();
    }));
  }
}
